package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Blogs;
import com.ruoyi.system.domain.Project;
import com.ruoyi.system.service.IBlogsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资讯页面Controller
 * 
 * @author ruoyi
 * @date 2023-09-26
 */
@RestController
@RequestMapping("/system/blogs")
public class BlogsController extends BaseController
{
    @Autowired
    private IBlogsService blogsService;

    
    @GetMapping("/app/list")
    public TableDataInfo Applist(Blogs blogs)
    {
        startPage();
        List<Blogs> list = blogsService.selectBlogsList(blogs);
        return getDataTable(list);
    }
    
    
    @GetMapping(value = "app/{id}")
    public AjaxResult getappInfo(@PathVariable("id") Long id)
    {
        return success(blogsService.selectBlogsById(id));
    }
    /**
     * 查询资讯页面列表
     */
    @PreAuthorize("@ss.hasPermi('system:blogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(Blogs blogs)
    {
        startPage();
        List<Blogs> list = blogsService.selectBlogsList(blogs);
        return getDataTable(list);
    }

    /**
     * 导出资讯页面列表
     */
    @PreAuthorize("@ss.hasPermi('system:blogs:export')")
    @Log(title = "资讯页面", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Blogs blogs)
    {
        List<Blogs> list = blogsService.selectBlogsList(blogs);
        ExcelUtil<Blogs> util = new ExcelUtil<Blogs>(Blogs.class);
        util.exportExcel(response, list, "资讯页面数据");
    }

    /**
     * 获取资讯页面详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:blogs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(blogsService.selectBlogsById(id));
    }

    /**
     * 新增资讯页面
     */
    @PreAuthorize("@ss.hasPermi('system:blogs:add')")
    @Log(title = "资讯页面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Blogs blogs)
    {
        return toAjax(blogsService.insertBlogs(blogs));
    }

    /**
     * 修改资讯页面
     */
    @PreAuthorize("@ss.hasPermi('system:blogs:edit')")
    @Log(title = "资讯页面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Blogs blogs)
    {
        return toAjax(blogsService.updateBlogs(blogs));
    }

    /**
     * 删除资讯页面
     */
    @PreAuthorize("@ss.hasPermi('system:blogs:remove')")
    @Log(title = "资讯页面", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blogsService.deleteBlogsByIds(ids));
    }
}
